package com.ymatou.iapi.pushbind.testcase;

import com.ymatou.iapi.pushbind.parameter.BuyerPushConfig;
import com.ymatou.iapi.pushbind.parameter.SavePushConfigBean;
import com.ymatou.iapi.pushbind.service.SavePushConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Map;
import java.util.Random;

/**
*保存买家推送配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SavePushConfig{
	private static SavePushConfigBean savepushconfigBean;
	private static SavePushConfigCall savepushconfigCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("保存买家推送配置");
	}

	@Before
	public void caseUp() {
		savepushconfigBean=new SavePushConfigBean();
		savepushconfigCall=new SavePushConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(savepushconfigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SavePushConfig_001() {
		Logger.start(true,"保存买家推送配置");
		try {
			BuyerPushConfig buyerPushConfig = new BuyerPushConfig();
			int userid = new Random().nextInt(10000);
			buyerPushConfig.setUserId(userid);
			buyerPushConfig.setInteractiveMsgSwitch(1);
			buyerPushConfig.setNotificationSwitch(1);
			buyerPushConfig.setOrderAssistantSwitch(1);
			buyerPushConfig.setPromotionsSwitch(1);
			savepushconfigBean.setConfigInfo(buyerPushConfig);
			savepushconfigCall.setData(savepushconfigBean);
			savepushconfigCall.callService();
			ImDefaultWapper im = new ImDefaultWapper();
			Map map = im.selectPushConfigByUserId(userid).get(0);
			Logger.verifyEquals(userid,Integer.parseInt(map.get("UserId").toString()),"验证UserId");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getPromotionsSwitch().toString(),map.get("PromotionsSwitch").toString(),"验证PromotionsSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getInteractiveMsgSwitch().toString(),map.get("InteractiveMsgSwitch").toString(),"验证InteractiveMsgSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getNotificationSwitch().toString(),map.get("NotificationSwitch").toString(),"验证NotificationSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getOrderAssistantSwitch().toString(),map.get("OrderAssistantSwitch").toString(),"验证OrderAssistantSwitch");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SavePushConfig_002() {
		Logger.start(true,"保存买家推送配置，修改保存配置");
		try {
			BuyerPushConfig buyerPushConfig = new BuyerPushConfig();
			int userid = new Random().nextInt(10000);
			buyerPushConfig.setUserId(userid);
			buyerPushConfig.setInteractiveMsgSwitch(1);
			buyerPushConfig.setNotificationSwitch(1);
			buyerPushConfig.setOrderAssistantSwitch(1);
			buyerPushConfig.setPromotionsSwitch(1);
			savepushconfigBean.setConfigInfo(buyerPushConfig);
			savepushconfigCall.setData(savepushconfigBean);
			savepushconfigCall.callService();
			ImDefaultWapper im = new ImDefaultWapper();
			Map map = im.selectPushConfigByUserId(userid).get(0);
			Logger.verifyEquals(userid,Integer.parseInt(map.get("UserId").toString()),"验证UserId");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getPromotionsSwitch().toString(),map.get("PromotionsSwitch").toString(),"验证PromotionsSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getInteractiveMsgSwitch().toString(),map.get("InteractiveMsgSwitch").toString(),"验证InteractiveMsgSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getNotificationSwitch().toString(),map.get("NotificationSwitch").toString(),"验证NotificationSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getOrderAssistantSwitch().toString(),map.get("OrderAssistantSwitch").toString(),"验证OrderAssistantSwitch");
			buyerPushConfig.setPromotionsSwitch(0);
			buyerPushConfig.setOrderAssistantSwitch(0);
			savepushconfigCall.callService();
			Map map1 = im.selectPushConfigByUserId(userid).get(0);
			Logger.verifyEquals(userid,Integer.parseInt(map1.get("UserId").toString()),"验证UserId");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getPromotionsSwitch().toString(),map1.get("PromotionsSwitch").toString(),"验证PromotionsSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getInteractiveMsgSwitch().toString(),map1.get("InteractiveMsgSwitch").toString(),"验证InteractiveMsgSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getNotificationSwitch().toString(),map1.get("NotificationSwitch").toString(),"验证NotificationSwitch");
			Logger.verifyEquals(savepushconfigBean.getConfigInfo().getOrderAssistantSwitch().toString(),map1.get("OrderAssistantSwitch").toString(),"验证OrderAssistantSwitch");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SavePushConfig_003() {
		Logger.start(true,"保存买家推送配置，userid为空");
		try {
			BuyerPushConfig buyerPushConfig = new BuyerPushConfig();
			buyerPushConfig.setInteractiveMsgSwitch(1);
			buyerPushConfig.setNotificationSwitch(1);
			buyerPushConfig.setOrderAssistantSwitch(1);
			buyerPushConfig.setPromotionsSwitch(1);
			savepushconfigBean.setConfigInfo(buyerPushConfig);
			savepushconfigCall.setData(savepushconfigBean);
			savepushconfigCall.callService();
			Logger.verifyEquals("406",savepushconfigCall.getString("Status"),"验证Status，参数错误");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}